/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.employee.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.chlitina.store.common.config.Global;
import com.chlitina.store.common.persistence.Page;
import com.chlitina.store.common.web.BaseController;
import com.chlitina.store.modules.employee.entity.StoreEmployeeAccountingDetail;
import com.chlitina.store.modules.employee.service.StoreEmployeeAccountingDetailService;

/**
 * 员工结算单明细Controller
 * @author liujiang
 * @version 2013-11-21
 */
@Controller
@RequestMapping(value = Global.ADMIN_PATH+"/employee/storeEmployeeAccountingDetail")
public class StoreEmployeeAccountingDetailController extends BaseController {

	@Autowired
	private StoreEmployeeAccountingDetailService storeEmployeeAccountingDetailService;
	
	@ModelAttribute
	public StoreEmployeeAccountingDetail get(@RequestParam(required=false) Long id) {
		if (id != null){
			return storeEmployeeAccountingDetailService.get(id);
		}else{
			return new StoreEmployeeAccountingDetail();
		}
	}
	
	@RequestMapping(value = {"list", ""})
	public String list(Long account_id, StoreEmployeeAccountingDetail storeEmployeeAccountingDetail, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<StoreEmployeeAccountingDetail> page = storeEmployeeAccountingDetailService.find(new Page<StoreEmployeeAccountingDetail>(request, response), account_id); 
        model.addAttribute("page", page);
		return "modules/employee/storeEmployeeAccountingDetailList";
	}

	@RequestMapping(value = "form")
	public String form(StoreEmployeeAccountingDetail storeEmployeeAccountingDetail, Model model) {
		model.addAttribute("storeEmployeeAccountingDetail", storeEmployeeAccountingDetail);
		return "modules/employee/storeEmployeeAccountingDetailForm";
	}

	@RequestMapping(value = "save")
	public String save(StoreEmployeeAccountingDetail storeEmployeeAccountingDetail, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, storeEmployeeAccountingDetail)){
			return form(storeEmployeeAccountingDetail, model);
		}
		storeEmployeeAccountingDetailService.save(storeEmployeeAccountingDetail);
		addMessage(redirectAttributes, "保存员工结算单明细成功");
		return "redirect:"+Global.ADMIN_PATH+"/employee/storeEmployeeAccountingDetail/";
	}
	
	@RequestMapping(value = "delete")
	public String delete(Long id, RedirectAttributes redirectAttributes) {
		storeEmployeeAccountingDetailService.delete(id);
		addMessage(redirectAttributes, "删除员工结算单明细成功");
		return "redirect:"+Global.ADMIN_PATH+"/employee/storeEmployeeAccountingDetail/";
	}

}
